package com.apptest.android;

import android.os.Bundle;
import android.widget.TextView;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.NavigationUI;

import com.apptest.android.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;
    private TextView mTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        BottomNavigationView navView = findViewById(R.id.bottom_nav_view);//使用binding的成员时无法绑定
        Toolbar mToolbar = findViewById(R.id.toolbar);
        mTitle=findViewById(R.id.toolbar_title);
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main);
        //使用navController无法再添加监听器
        navController.addOnDestinationChangedListener((controller, destination, arguments) -> {
            mTitle.setText(destination.getLabel().toString());
        });
        NavigationUI.setupWithNavController(navView, navController);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, binding.drawerLayout, mToolbar,
                R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        toggle.syncState();
        binding.drawerLayout.addDrawerListener(toggle);

        //setSupportActionBar(mToolbar);
    }

    private void initListener(){

    }

}